package com.wlc.fanxing.testfanxing;

import java.util.ArrayList;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 测试范型
 * @date 2021-07-13 17:08
 */
public class TestDemo {
   /* public static void iterate(ArrayList<Hero> list) {
        for (Hero hero : list) {
            System.out.println(hero);
        }
    }

    public static void iterateAP(ArrayList<APHero> list) {
        for (Hero hero : list) {
            System.out.println(hero.name);
        }
    }

    public static void iterateAD(ArrayList<ADHero> list) {
        for (Hero hero : list) {
            System.out.println(hero.name);
        }
    }*/

    public static void loop(ArrayList<? extends Hero> list){
        for (Hero hero:list){
            //System.out.println(hero.getName() );
            System.out.println(hero.getName() );
        }
    }

    public static void main(String[] args) {
        ArrayList<Hero> hs = new ArrayList<>();
        hs.add(new Hero("abc",20));
        hs.add(new Hero("abc2",20));
        hs.add(new Hero("abc3",20));
        ArrayList<APHero> aphs = new ArrayList<>();
        aphs.add(new APHero("def",20));
        aphs.add(new APHero("def2",20));
        aphs.add(new APHero("def3",20));
        ArrayList<ADHero> adhs = new ArrayList<>();
        adhs.add(new ADHero("kkk",20));
        adhs.add(new ADHero("kkk2",20));
        adhs.add(new ADHero("kkk3",20));

        loop(hs);
        loop(aphs);
        loop(adhs);
    }
}
